<?php

namespace App\Models;

use Dcat\Admin\Traits\HasDateTimeFormatter;

use Illuminate\Database\Eloquent\Model;

class Business extends Model
{
	use HasDateTimeFormatter;
    protected $table = 'business';
    public function setPetIdsAttribute($value)
    {
        $this->attributes['pet_ids'] = json_encode($value);
    }
    public function setServiceProjectIdsAttribute($value)
    {
        $this->attributes['service_project_ids'] = json_encode($value);
    }
    public function setServiceProjectNeedsAttribute($value)
    {
        $this->attributes['service_project_needs'] = json_encode($value);
    }
    public function setStartDateAttribute($value)
    {
        $this->attributes['start_date'] = json_encode($value);
    }

    public function getPetIdsAttribute($value)
    {
        return json_decode($value,true);
    }
    public function getServiceProjectIdsAttribute($value)
    {
        return json_decode($value,true);
    }

    public function getStartDateAttribute($value)
    {
        return json_decode($value,true);
    }
    public function getServiceProjectNeedsAttribute($value)
    {
        $data=json_decode($value,true);
        return  array_map(function ($item){
            if(isset($item['image'])){
                $item['image']=createFullUrl($item['image']);
            }
            return $item;
        },$data);
    }
}
